package org.aersoft.jokebook.adapters;

import java.util.ArrayList;

import org.aersoft.jokebook.R;
import org.aersoft.jokebook.activities.CategoryActivity;
import org.aersoft.jokebook.beans.ItemBean;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

/**
 * Adapter class to convert an array of {@link br.com.jokebook.beans.ItemBean}
 * objects in a list of different informations to be showed on
 * {@link CategoryActivity} layout.
 * @author Danilo de Godoy Carolino.
 */
public class ItemListAdapter extends ArrayAdapter<ItemBean> {


	private final Context context;
	private final ArrayList<ItemBean> values;

	/**
	 * Constructor method of adapter class.
	 * @param context of {@link Context} type.
	 * @param values of {@link ArrayList} type.
	 */
	public ItemListAdapter(Context context, int textViewResourceId, ArrayList<ItemBean> values) {
		super(context, textViewResourceId, values);
		this.context = context;
		this.values = values;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ItemBean obj = values.get(position);
		if (convertView == null) {
			LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(R.layout.list_joke_by_category, parent, false);
		}
		if (obj != null) {
			TextView title = (TextView) convertView.findViewById(R.id.title);
			TextView description = (TextView) convertView.findViewById(R.id.description);
			title.setText(obj.getTitle());
			description.setText(obj.getDescription());
		}
		return convertView;
	}
}
